//
//  main.m
//  计算喝啤酒
//
//  Created by 陶建 on 2017/7/11.
//  Copyright © 2017年 taoJ. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        NSLog(@"Hello, World!");
    }
    return 0;
}


// 10块钱喝啤酒算法
void drink() {
    int totalMoney = 10;
    int unitPrice = 2;
    int bottleRedemption = 2;
    int bottleCapRedemption = 4;
    
    int count = 0;
    int bottle = 0;
    int bottleCap = 0;
    while (1) {
        if (bottle >= bottleRedemption) {
            count = count + 1;
            bottle = bottle + 1 - bottleRedemption;
            bottleCap = bottleCap + 1;
            continue;
        }
        
        if (bottleCap >= bottleCapRedemption) {
            count = count + 1;
            bottle = bottle + 1;
            bottleCap = bottleCap + 1 - bottleCapRedemption;
            continue;
        }
        totalMoney = totalMoney - unitPrice;
        if (totalMoney < 0) break;
        count = count + 1;
        bottle = bottle + 1;
        bottleCap = bottleCap + 1;
    }
    NSLog(@"%d", count);
}
